package com.xyz.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.xyz.entity.R;

import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author zsr
 * @date 2021/6/27 18:37
 */
public class ResponseUtil {
    public static void out(HttpServletResponse response, R r) {
        try {
            response.setStatus(HttpServletResponse.SC_OK);
            response.setContentType("application/json;charset=UTF-8");
            response.setCharacterEncoding("UTF-8");

            ObjectMapper mapper = new ObjectMapper();
            String json = mapper.writeValueAsString(r);

            response.getWriter().write(json);
            response.getWriter().flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
